/* Ty, a programming language interpreter
 * Copyright (C) 2007 Nick Thomas
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * The driver takes care of interacting with JACK and ALSAseq. It communicates
 * with an Engine, which accepts MIDI commands and produces audio for the driver
 * to output.
 */

#ifndef TY_DATA_STACK_H
#define TY_DATA_STACK_H

/* The data stack is implemented as a simple array of objects, growing from
 * the front of the array to the back of the array. When we hit the back of
 * the array, we simply reallocate entire stack with twice the size.
 */

#include "data.h"

#define TY_STACK_INITIAL_SIZE 64

typedef struct {
    uintptr_t top;
    uintptr_t size;
    ty_obj *data;
} ty_data_stack;

/* Initializes the given stack. */
void ty_make_stack(ty_data_stack *stack);

/* Pushes the given object onto the given stack. */
void ty_push(ty_data_stack *stack, ty_obj obj);

/* Returns 0 on success, and 1 on stack underflow. */
int ty_pop(ty_data_stack *stack, ty_obj *obj);

/* Unit tests. */
void ty_test_data_stack(CuTest *tc);

#endif
